<?php
declare (strict_types = 1);

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\api\model\Domains as DomainsModel;
use app\Request;

class Domains extends Base
{

    /**
     * 域列表
     * @param $page 页面
     * @param $pagesize 每页大小
     * @return \think\response\Json
     */
    public function domainslist($page,$pagesize){
        try {
            $DomainsModel = new DomainsModel();
            $list = $DomainsModel->DomainsList($page,$pagesize);
            return json($list);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 新增域
     * @param $key  域唯一标识
     * @param $domain 域
     * @param $exp_time 过期时间
     * @param $status
     * @return \think\response\Json
     */
    public function domainsadd($key,$domain,$exp_time,$status=1){
        try {
            $DomainsModel = new DomainsModel();
            $res = $DomainsModel->DomainsAdd($key,$domain,$exp_time,$status);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 保存域
     * @param $id
     * @param $key
     * @param $domain
     * @param $exp_time
     * @return \think\response\Json
     */
    public function domainsedit($id,$key,$domain,$exp_time){
        try {
            $DomainsModel = new DomainsModel();
            $res = $DomainsModel->DomainsEdit($id,$key,$domain,$exp_time);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 域启/禁用
     * @param $id
     * @param $status
     * @return \think\response\Json
     */
    public function domainssetstatus($id,$status){
        try {
            $DomainsModel = new DomainsModel();
            $res = $DomainsModel->DomainsSetStatus($id,$status);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

    /**
     * 域删除
     * @param $id
     * @return \think\response\Json
     */
    public function domainsdel($id){
        try {
            $DomainsModel = new DomainsModel();
            $res = $DomainsModel->DomainsDel($id);
            return json($res);
        } catch (\Exception $e) {
            $error = ['status'=>false,'code'=>$e->getCode(),'msg'=>$e->getMessage(),'data'=>''];
            return json($error);
        }
    }

}
